package com.test.controller;

import com.github.pagehelper.PageInfo;
import com.test.pojo.House;
import com.test.service.HouseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/house")
@CrossOrigin(origins = "*")
public class HouseController {

    @Autowired
    private HouseService houseService;

    /**
     * 分页查询
     * pageNum  当前页（默认1）
     * pageSize 每页条数（默认5）
     */
    @GetMapping("/list")
    public PageInfo<House> list(
            @RequestParam(required = false) String title,
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "5") Integer pageSize) {
        return houseService.findHouseLikeTitle(title, pageNum, pageSize);
    }
    @DeleteMapping("/batch")
    public String deleteHouseByIds(@RequestBody Integer[] ids) {
        houseService.deleteHouseByIds(ids);
        return "删除成功";
    }
    @PostMapping
    public String addHouse(@RequestBody House house) {
        houseService.insertHouse(house);
        return "新增成功";
    }
    @PutMapping
    public String updateHouseById(@RequestBody House house) {
        houseService.updateHouseById(house);
        return "修改成功";
    }
}